<template>
  <div class="app-container">
    <el-tabs type="border-card">
      <el-tab-pane label="新消息">
        <el-row style="padding:10px 0">
          <el-col :span="5">
            <el-input placeholder="请输入消息标题" v-model="this.listQueryNew.queryName"></el-input>
          </el-col>
          <el-button type="primary" icon="el-icon-search" style="margin-left:20px">搜索</el-button>
        </el-row>
        <el-divider content-position="left">最新</el-divider>
        <el-table
          v-loading="listLoading1"
          :data="newList"
          border
          fit
          highlight-current-row
          style="width: 100%"
        >
          <el-table-column align="center" label="编号" width="80">
            <template slot-scope="scope">
              <span>{{ scope.row.id }}</span>
            </template>
          </el-table-column>

          <el-table-column min-width="300px" label="标题" width="400">
            <template slot-scope="{row}">
              <span>{{ row.msgTitle }}</span>
            </template>
          </el-table-column>

          <el-table-column class-name="status-col" label="消息级别" width="200">
            <template slot-scope="scope">
              <span v-if="scope.row.msgLevel == 1">一般</span>
              <span v-if="scope.row.msgLevel == 2">重要</span>
              <span v-if="scope.row.msgLevel == 3">紧急</span>
            </template>
          </el-table-column>

          <el-table-column align="center" label="操作">
            <template slot-scope="scope">
              <router-link :to="'/message/messageDetail/'+scope.row.id+'/reply'">
                <el-button type="primary" size="small" icon="el-icon-edit">回复</el-button>
              </router-link>
              <router-link :to="'/message/messageDetail/'+scope.row.id+'/check'">
                <el-button size="small" icon="el-icon-view">查看</el-button>
              </router-link>
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="totalNew>0"
          :total="totalNew"
          :page.sync="listQueryNew.curPage"
          :limit.sync="listQueryNew.pageSize"
          @pagination="getNewMsgList"
        />
      </el-tab-pane>
      <el-tab-pane label="已阅消息">
        <el-row style="padding:10px 0">
          <el-col :span="5">
            <el-input placeholder="请输入消息标题" v-model="this.listQueryRead.queryName"></el-input>
          </el-col>
          <el-button type="primary" icon="el-icon-search" style="margin-left:20px">搜索</el-button>
        </el-row>
        <el-divider content-position="left">已阅</el-divider>
        <el-table
          v-loading="listLoading2"
          :data="readList"
          border
          fit
          highlight-current-row
          style="width: 100%"
        >
          <el-table-column align="center" label="编号" width="80">
            <template slot-scope="scope">
              <span>{{ scope.row.id }}</span>
            </template>
          </el-table-column>

          <el-table-column min-width="300px" label="标题" width="400">
            <template slot-scope="{row}">
              <span>{{ row.msgTitle }}</span>
            </template>
          </el-table-column>

          <el-table-column class-name="status-col" label="消息级别" width="200">
            <template slot-scope="scope">
              <span v-if="scope.row.msgLevel == 1">一般</span>
              <span v-if="scope.row.msgLevel == 2">重要</span>
              <span v-if="scope.row.msgLevel == 3">紧急</span>
            </template>
          </el-table-column>

          <el-table-column align="center" label="操作">
            <template slot-scope="scope">
              <router-link :to="'/message/messageDetail/'+scope.row.id+'/reply'">
                <el-button type="primary" size="small" icon="el-icon-edit">回复</el-button>
              </router-link>
              <router-link :to="'/message/messageDetail/'+scope.row.id+'/check'">
                <el-button size="small" icon="el-icon-view">查看</el-button>
              </router-link>
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="totalRead>0"
          :total="totalRead"
          :page.sync="listQueryRead.curPage"
          :limit.sync="listQueryRead.pageSize"
          @pagination="getReadMsgList"
        />
      </el-tab-pane>
      <el-tab-pane label="已回复消息">
        <el-row style="padding:10px 0">
          <el-col :span="5">
            <el-input placeholder="请输入消息标题" v-model="this.listQueryReply.queryName"></el-input>
          </el-col>
          <el-button type="primary" icon="el-icon-search" style="margin-left:20px">搜索</el-button>
        </el-row>
        <el-divider content-position="left">已回复</el-divider>
        <el-table
          v-loading="listLoading3"
          :data="replyList"
          border
          fit
          highlight-current-row
          style="width: 100%"
        >
          <el-table-column align="center" label="编号" width="80">
            <template slot-scope="scope">
              <span>{{ scope.row.id }}</span>
            </template>
          </el-table-column>

          <el-table-column min-width="300px" label="标题" width="400">
            <template slot-scope="{row}">
              <router-link :to="'/message/messageDetail/'+row.id+'/check'" class="link-type">
                <span>{{ row.msgTitle }}</span>
              </router-link>
            </template>
          </el-table-column>

          <el-table-column class-name="status-col" label="消息级别" width="200">
            <template slot-scope="scope">
              <span v-if="scope.row.msgLevel == 1">一般</span>
              <span v-if="scope.row.msgLevel == 2">重要</span>
              <span v-if="scope.row.msgLevel == 3">紧急</span>
            </template>
          </el-table-column>

          <el-table-column align="center" label="操作">
            <template slot-scope="scope">
              <router-link :to="'/message/messageDetail/'+scope.row.id+'/check'">
                <el-button size="small" icon="el-icon-view">查看</el-button>
              </router-link>
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="totalReply>0"
          :total="totalReply"
          :page.sync="listQueryReply.curPage"
          :limit.sync="listQueryReply.pageSize"
          @pagination="getRepliedMsgList"
        />
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import {
  fetchNewMsgList,
  fetchReadMsgList,
  fetchRepliedMsgList
} from '@/api/message'
import Pagination from '@/components/Pagination' // Secondary package based on el-pagination

export default {
  name: 'MessageList',
  components: { Pagination },
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'info',
        deleted: 'danger'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      // list: null,
      newList: [], //最新消息
      readList: [], //已读消息
      replyList: [], //已回复消息
      totalNew: 0,
      totalRead: 0,
      totalReply: 0,
      listLoading1: true,
      listLoading2: true,
      listLoading3: true,
      listQueryNew: {
        curPage: 1,
        pageSize: 10,
        queryName: '',
        userId: this.$store.getters.userId
      },
      listQueryRead: {
        curPage: 1,
        pageSize: 10,
        queryName: '',
        userId: this.$store.getters.userId
      },
      listQueryReply: {
        curPage: 1,
        pageSize: 10,
        queryName: '',
        userId: this.$store.getters.userId
      },
      input2: ''
    }
  },
  created() {
    this.getNewMsgList()
    this.getReadMsgList()
    this.getRepliedMsgList()
  },
  methods: {
    getNewMsgList() {
      this.listLoading1 = true
      fetchNewMsgList(this.listQueryNew).then((response) => {
        this.newList = response.data.records
        this.totalNew = response.data.total
        this.listLoading1 = false
      })
    },
    getReadMsgList() {
      this.listLoading2 = true
      fetchReadMsgList(this.listQueryRead).then((response) => {
        console.log(response.data.records)
        this.readList = response.data.records

        this.totalRead = response.data.total
        this.listLoading2 = false
      })
    },
    getRepliedMsgList() {
      this.listLoading3 = true
      fetchRepliedMsgList(this.listQueryReply).then((response) => {
        this.replyList = response.data.records
        this.totalReply = response.data.total
        this.listLoading3 = false
      })
    }
  }
}
</script>

<style scoped  lang="scss" >
@import '~@/styles/mixin.scss';
.app-container /deep/ .pagination-container {
  margin-top: 0;
  padding: 16px 16px;
}
.edit-input {
  padding-right: 100px;
}
.cancel-btn {
  position: absolute;
  right: 15px;
  top: 10px;
}

.createPost-container {
  position: relative;

  .createPost-main-container {
    padding: 40px 45px 20px 50px;

    .postInfo-container {
      position: relative;
      @include clearfix;
      margin-bottom: 10px;

      .postInfo-container-item {
        float: left;
      }
    }
  }

  .word-counter {
    width: 40px;
    position: absolute;
    right: 10px;
    top: 0px;
  }
}
</style>
